﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace QlrrPrintService.Common.Command
{
    public class PrintPaperTemplate:IToTSPLCommand
    {

        #region 构造函数

        public PrintPaperTemplate() { }

        public PrintPaperTemplate(string id) 
        {
            _id = id;
        }

        #endregion

        #region 变量

        protected string _id;
        public string Id
        {
            get { return _id; }
            set { _id = value; }
        }

        /// <summary>
        /// 定义打印纸的大小
        /// </summary>
        protected Size _size = new Size();
        public Size Size
        {
            get { return _size; }
            set { _size = value; }
        }

        /// <summary>
        /// 定義兩張標籤之間的間隙距離
        /// GAP m,n
        /// m定義標籤間隙高度 (英吋或公釐)0  m  1 (inch), 0  m  25.4 (mm)
        /// n定義標籤間隙高度的補償值
        /// </summary>
        private Gap _gap = null;
        public Gap Gap
        {
            get { return _gap; }
            set { _gap = value; }
        }

        /// <summary>
        /// 設定黑標高度及使用者定義標籤印完後標籤額外送出的長度
        /// </summary>
        private Bline _bline = null;
        public Bline Bline
        {
            get { return _bline; }
            set { _bline = value; }
        }

        private Offset _offset = null;
        /// <summary>
        /// 定義標籤於列印完後額外推出的長度，特別是在使用自動剝紙器或裁刀功能時，
        /// 可用來調校標籤停止的位置，在列印下一張時印表機會將原先多推出或少推
        /// 出的部份以回拉方式補償回來
        /// </summary>
        public Offset Offset
        {
            get { return _offset; }
            set { _offset = value; }
        }

        /// <summary>
        /// 打印速度
        /// </summary>
        protected Speed _speed = null;
        public Speed Speed
        {
            get { return _speed; }
            set { _speed = value; }
        }

        /// <summary>
        /// 打印浓度
        /// </summary>
        protected Density _density = null;
        public Density Density
        {
            get { return _density; }
            set { _density = value; }
        }

        /// <summary>
        /// 設定列印方向及鏡射功能，此設定將被記錄於
        /// </summary>
        protected Direction _direction = null;
        public Direction Direction
        {
            get { return _direction; }
            set { _direction = value; }
        }

        /// <summary>
        /// 定義標籤紙上的相對於原點的參考點座標X水平座標
        /// </summary>
        protected Reference _reference;
        public Reference Reference
        {
            get { return _reference; }
            set { _reference = value; }
        }


        /// <summary>
        /// 將標籤紙向前推送指定的長度
        /// </summary>
        private Feed _feed=null;
        public Feed Feed
        {
            get { return _feed; }
            set { _feed = value; }
        }

        /// <summary>
        /// 將標籤紙向後回拉指定的長度
        /// </summary>
        private Backfeed _backFeed;
        public Backfeed BackFeed
        {
            get { return _backFeed; }
            set { _backFeed = value; }
        }
        
        /// <summary>
        /// 將標籤向前推送至下一張標籤的起始位置
        /// </summary>
        protected FormFeed _formFeed = null;
        public FormFeed FormFeed
        {
            get { return _formFeed; }
            set { _formFeed = value; }
        }

        /// <summary>
        /// 在使用含有間隙或黑標的標籤紙時，若不能確定第一張標籤紙是否在正確列印位置時，
        /// 此指令可將標籤紙向前推送至下一張標籤紙的起點開始列印
        /// </summary>
        protected Home _home = null;
        public Home Home
        {
            get { return _home; }
            set { _home = value; }
        }


        protected List<Bar> _printLines;
        public List<Bar> PriltLines
        {
            get { return _printLines; }
            set { _printLines = value; }
        }

        protected List<BitmapCommand> _printBitmaps;
        public List<BitmapCommand> PrintBitmaps
        {
            get { return _printBitmaps; }
            set { _printBitmaps = value; }
        }

        protected List<QRCode> _printQRCodes;
        public List<QRCode> PrintQRCodes
        {
            get { return _printQRCodes; }
            set { _printQRCodes = value; }
        }


        protected string _templateCommand;
        [Newtonsoft.Json.JsonIgnore]
        public string TemplateCommand
        {
            get { return _templateCommand; }
        }

       

        #endregion




        #region IToTSPLCommand 成员

        public byte[] ToTSPLCommandByte(int mm_to_dot)
        {
            throw new NotImplementedException();
        }

        public string ToTSPLCommandAscii(int mm_to_dot)
        {
            if (_templateCommand == null)
            {
                StringBuilder stringBuilder = new StringBuilder();
                if (_size != null)
                {
                    stringBuilder.Append(_size.ToTSPLCommandAscii(mm_to_dot));
                }

                if (_gap != null)
                {
                    stringBuilder.Append(_gap.ToTSPLCommandAscii(mm_to_dot));
                }

                if (_bline != null)
                {
                    stringBuilder.Append(_bline.ToTSPLCommandAscii(mm_to_dot));
                }

                if (_offset != null)
                {
                    stringBuilder.Append(_offset.ToTSPLCommandAscii(mm_to_dot));
                }

                if (_speed != null)
                {
                    stringBuilder.Append(_speed.ToTSPLCommandAscii(mm_to_dot));
                }

                if (_density != null)
                {
                    stringBuilder.Append(_density.ToTSPLCommandAscii(mm_to_dot));
                }

                if (_direction != null)
                {
                    stringBuilder.Append(_direction.ToTSPLCommandAscii(mm_to_dot));
                }

                if (_reference != null)
                {
                    stringBuilder.Append(_reference.ToTSPLCommandAscii(mm_to_dot));
                }

                if (_feed != null)
                {
                    stringBuilder.Append(_feed.ToTSPLCommandAscii(mm_to_dot));
                }

                if (_backFeed != null)
                {
                    stringBuilder.Append(_backFeed.ToTSPLCommandAscii(mm_to_dot));
                }

                if (_formFeed != null)
                {
                    stringBuilder.Append(_formFeed.ToTSPLCommandAscii(mm_to_dot));
                }

                if (_home != null)
                {
                    stringBuilder.Append(_home.ToTSPLCommandAscii(mm_to_dot));
                }

                stringBuilder.Append(new Cls().ToTSPLCommandAscii(mm_to_dot));
             

                _templateCommand = stringBuilder.ToString();

            }
            return _templateCommand;
            
        }

        #endregion
    }
}
